<?php
declare (strict_types = 1);

namespace app\api\controller\v1;


use think\facade\Request;
use app\api\service\StatusCode;
use app\api\service\UserToken;
use app\api\model\Section as ModelSection;
use app\api\validate\ParamMustBePostiveInt;
use app\api\validate\Section as ValidateSection;

/**
 * 教师端课程管理类
 */
class Section extends Api
{

    /**
     * 
     * 获取小节内容
     */
    
    public function index()
    {
        $id = (new ParamMustBePostiveInt())->paramCheck();
        $content = ModelSection::getContent($id);
        $this->return_msg(StatusCode::SUCCESS,'数据获取成功', $content);
    }

    /**
     * 
     * 删除小节
     */

    public function delete()
    {
        $id = (new ParamMustBePostiveInt())->paramCheck();
        $success = ModelSection::delSection($id);
        exit(json_encode($success));
    }

    /**
     * 
     * 新增小节
     */

    public function create()
    {
        $data = Request::post();
        validate(ValidateSection::class)->scene('addSection')->check($data);
        $data["user_id"] = UserToken::getCurrentUid();
        $success = ModelSection::addSection($data);
        $this->return_msg(StatusCode::SUCCESS,'新增成功', $success);
    }

    /**
     * 
     * 修改小节
     */

     public function update()
     {
        $data = Request::post();
        validate(ValidateSection::class)->scene('updateSection')->check($data);
        $success = ModelSection::updateSection($data);
        exit(json_encode($success));
     }
}